// api 统一管理

// base + url  
const smsUrl = '/app/code/sms'
const hotSearchUrl = '/ebapi/store_api/hot_search';
const indexUrl = '/ebapi/public_api/index';
const user = 'app'
const addressUrl = '/app/receiveraddress/'
const orderUrl = '/app/order/'
const product = "/product";
const comUrl = '/app/comment';
const afterSale = 'app/aftersale';
const reminderUrl = '/app/userreminder/'
// 七牛云
const uploadQiniuUrl = '/app/uploadtoken/qiniu'

// 此处第二个参数vm，就是我们在页面使用的this，你可以通过vm获取vuex等操作，更多内容详见uView对拦截器的介绍部分：
// https://uviewui.com/js/http.html#%E4%BD%95%E8%B0%93%E8%AF%B7%E6%B1%82%E6%8B%A6%E6%88%AA%EF%BC%9F
const install = (Vue, vm) => {
	// 此处没有使用传入的params参数
	let getSearch = (params = {}) => vm.$u.get(hotSearchUrl, {
		id: 2
	});

	// 此处使用了传入的params参数，一切自定义即可
	let getInfo = (params = {}) => vm.$u.post(indexUrl, params);

	// let user = '/app'
	let getsms = (p) => vm.$u.post(smsUrl+'?phone='+p.phone)
	let login = (params = {}) => vm.$u.post(user + '/login', params);
	let getUserId = () => vm.$u.get(user + '/userId');
	let getUserInfo = (params = {}) => vm.$u.get(user + '/userInfo', params);

	// 地址;
	let getUserAddressAll = () => vm.$u.get(addressUrl + '/all');
	let addUserAddress = (params) => vm.$u.post(addressUrl, params)
	let editUserAddress = (params = {}) => vm.$u.put(addressUrl + vm.$store.addressEditId, params)
	let deteleUserAddress = () => vm.$u.delete(addressUrl + vm.$store.addressEditId)

	// 菜单;
	let getGood = (id = {}) => vm.$u.get(product + '/info/' + id.id)
	let getALLgoods = (params = {}) => vm.$u.get(product + "/listwithsaleattr")

	// 订单
	let getOrderAll = () => vm.$u.get(orderUrl + 'all')
	let getOrderDetail = (p) => vm.$u.get(orderUrl + p.sn)
	let pushOrder = (params = {}) => vm.$u.post(orderUrl, params)
	let payOrder = (params = {}) => vm.$u.get(orderUrl + 'pay?orderSn=' + params.sn+'&returnUrl='+params.returnUrl)
	let overOrder = (params = {}) => vm.$u.put(orderUrl + params.sn + '/receive')
	let cancelOrder = (params = {}) => vm.$u.put(orderUrl + params.sn + '/cancel')

	// 售后
	let getAfterSale = (p) =>vm.$u.get(`${afterSale}?orderSn=`+p.sn)
	let applyAfterSale = (p)=>vm.$u.post(`${afterSale}/`,p)

	// 评论
	let getCom = (params = {}) => vm.$u.get(comUrl + '?orderSn=' + params.sn)
	let addCom = (params = {}) => vm.$u.post(comUrl + "//", params)
	// 商家所有评论
	let getStoreAllCom = (params = {}) =>
		vm.$u.get(comUrl + '/list?tag=' + params.tag)

	// 消息通知
	let getAllReminder = () => vm.$u.get(reminderUrl + "list?params=1")
	let putAllReminder = () => vm.$u.put(reminderUrl + "/all")
	let getReadedReminder = (params) => vm.$u.get(reminderUrl + "/" + params.id)
	// 七牛云
	let getCDNToken = () => vm.$u.post(uploadQiniuUrl)

	// 将各个定义的接口名称，统一放进对象挂载到vm.$u.api(因为vm就是this，也即this.$u.api)下
	vm.$u.api = {
		// getSearch,
		// getInfo,
		getsms, // 获取短信
		login, // 登录
		getUserId, // 获取id
		getUserInfo, // 获取用户信息
		// 地址;
		getUserAddressAll,
		addUserAddress,
		editUserAddress,
		deteleUserAddress,
		// 订单
		getOrderAll,
		getOrderDetail,
		pushOrder,
		payOrder,
		overOrder,
		cancelOrder,
		// 售后
		getAfterSale,
		applyAfterSale,
		// 商品;
		getGood,
		getALLgoods,
		// 订单评论
		getCom,
		addCom,
		getStoreAllCom,
		getCDNToken,
		// 消息通知
		getAllReminder,
		putAllReminder,
		getReadedReminder
	};

}

export default {
	install
}